// 订单商品
var express = require('express');
var router = express.Router();
const addressesService = require('../service/addressesService');

//增加匹配 
router.post('/', async function (req, res) {

    let data = await addressesService.insert(req.body)
    res.send(data);
})



//删除匹配
router.delete('/:id', async function (req, res) {
    let data = await addressesService.delete(req.params.id)
    res.send(data);
})

//修改匹配
router.put('/id', async function (req, res) {
    console.log(req.body);
    let id = req.body.id;
    // let data = await addressesService.update(req.params.id, req.body)
    let data = await addressesService.update(id, req.body)
    res.send(data);
})




//分页所有/条件查询
router.get('/all', async function (req, res) {
    let { type, value, current, size } = req.query;
    console.log("type, value", type, value);
    let searchObj = {};
    if (type) { searchObj[type] = value  }   // 使用正则可以实现模糊查询

    let data = await addressesService.find(searchObj, { current: current || 1, size: size || 5 })
    res.send(data);
})



module.exports = router;


